package com.epfresh.global;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;

import com.epfresh.activity.AuthorizeCheckActivity;
import com.epfresh.activity.LoginActivity;
import com.epfresh.api.entity.*;
import com.epfresh.api.global.AppActivity;
import com.epfresh.api.helper.ApplicationHelper;
import com.epfresh.api.http.OnRequestListener;
import com.umeng.analytics.MobclickAgent;

/**
 * Created by wzh on 16-6-30.
 */
public class BaseActivity extends AppActivity {
    public Context mContext = this;


    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
    }

    @Override
    protected void onDestroy() {

        super.onDestroy();
    }


    @Override
    public <T> void request(Object data, Object tag, OnRequestListener<T> onRequestListener) {
        if (data instanceof RequestEntity) {
            if (((RequestEntity) data).getCityId() == null || "".equals(((RequestEntity) data).getCityId()))
                ((RequestEntity) data).setCityId(ApplicationHelper.getInstance().getCity().getCityId());
        }
        super.request(data, tag, onRequestListener);
    }

    @Override
    public void onLogin() {
        Intent intent = new Intent(this, LoginActivity.class);
        startActivity(intent);
    }

    @Override
    public void accountAuthCheck() {
        Intent intent = new Intent(this, AuthorizeCheckActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }
}
